package com.lmh.config;


import com.lmh.job.OfflineAnalyticJob;
import com.lmh.utils.ThreadPool;


import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @program code
 * @Description
 * @Author limeihua
 * @Date 2024/07/22 18:03
 * @Version 1.0
 */
public class TaskConfig {
    private static ThreadPoolExecutor threadPoolExecutor;
    private static BlockingQueue<Runnable> queue;

    private static final ConcurrentHashMap<String, Future> taskMap = new ConcurrentHashMap<>();

    static {
        threadPoolExecutor = ThreadPool.getThreadPoolExecutor();
        queue = threadPoolExecutor.getQueue();
    }
    public static void addTask(Runnable runnable){
        Future<?> result = threadPoolExecutor.submit(runnable);
        OfflineAnalyticJob job = (OfflineAnalyticJob) runnable;
        taskMap.put(job.getOfflineAnalyticTemplate().getSqlID(), result);
    }


    public static void remove(String[] args) throws Exception {
        for (String arg : args) {
            if(taskMap.containsKey(arg)){
                Future<?> future = taskMap.get(arg);
                future.cancel(true);
                threadPoolExecutor.shutdown();
                System.out.println("已经终止任务：" + arg);
            }
        }
    }

    public static void analyticExecute(String sqlContent){

    }
}
